﻿  IF OBJECT_ID('up_MapHtml_GpsVisitXmissionStructureSelectClosest') IS not NULL
DROP PROC up_MapHtml_GpsVisitXmissionStructureSelectClosest

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'up_MapHtml_GpsVisitXmissionStructureSelectClosest')
	DROP PROCEDURE up_MapHtml_GpsVisitXmissionStructureSelectClosest
GO
 
 
 CREATE PROCEDURE [dbo].[up_MapHtml_GpsVisitXmissionStructureSelectClosest] 
(
	@latitude	float,
	@longitude	float,
	@key		int
)
AS

DECLARE @IdList varchar(MAX)
SET @IdList = ''

SELECT	
	@IdList = @IdList + CONVERT(varchar, Vendor_Visit_XMissionStructures_PoleId) + ','
FROM	
	tb_Vendor_Visit_XMissionStructures_Poles assets
WHERE	
	dbo.fn_DistanceBetween(assets.Latitude, assets.Longitude, @latitude, @longitude) < 2000

SELECT @IdList
